16cd28cd8e445a2e422a1955f472396c24475460,opennms-provision/opennms-provision-persistence/src/main/java/org/opennms/netmgt/provision/persist/DefaultNodeProvisionService.java,DefaultNodeProvisionService,provisionNode,#String#String#String#String#String[]#String#String#String#String#String#String#String#,64
Before Change
OnmsDistPoller dp = m_distPollerDao.get("localhost");
OnmsNode node = new OnmsNode();
node.setDistPoller(dp);
node.setType("A");
node.setForeignSource(foreignSource);
node.setForeignId(foreignId);
node.setLabel(nodeLabel);
OnmsIpInterface iface = new OnmsIpInterface();
iface.setNode(node);
iface.setIpAddress(ipAddress);
iface.setIsManaged("M");
iface.setIsSnmpPrimary(new PrimaryType('P'));
node.addIpInterface(iface);
Set<OnmsMonitoredService> services = new TreeSet<OnmsMonitoredService>();
services.add(new OnmsMonitoredService(iface, getServiceType("ICMP")));
services.add(new OnmsMonitoredService(iface, getServiceType("SNMP")));
iface.setMonitoredServices(services);
OnmsAssetRecord asset = new OnmsAssetRecord();
asset.setAutoenable(autoEnable);
asset.setConnection(accessMethod);
asset.setEnable(enablePassword);
asset.setUsername(deviceUsername);
asset.setPassword(devicePassword);
node.setAssetRecord(asset);
log().debug("saving database node");
m_nodeDao.save(node);
After Change
}
@Transactional
public boolean provisionNode(String foreignSource, String foreignId, String nodeLabel, String ipAddress,
String[] categories, String snmpCommunity, String snmpVersion,
String deviceUsername, String devicePassword, String enablePassword,
String accessMethod, String autoEnable) throws NodeProvisionException {
if (log().isDebugEnabled()) {
log().debug(String.format("adding SNMP community %s (%s)", snmpCommunity, snmpVersion));
}
// Set the SNMP community name (if necessary)
if (snmpCommunity != null && snmpVersion != null) {
try {
SnmpEventInfo info = new SnmpEventInfo();
info.setCommunityString(snmpCommunity);
info.setFirstIPAddress(ipAddress);
info.setVersion(snmpVersion);
m_snmpPeerFactory.define(info);
SnmpPeerFactory.saveCurrent();
} catch (Exception e) {
throw new NodeProvisionException("unable to add SNMP community information", e);
}
}
log().debug("creating requisition node");
// Create a requisition node based on the form input
RequisitionInterface reqIface = new RequisitionInterface();
reqIface.setIpAddr(ipAddress);
reqIface.setManaged(true);
reqIface.setSnmpPrimary("P");
reqIface.setStatus(1);
reqIface.putMonitoredService(new RequisitionMonitoredService("ICMP"));
reqIface.putMonitoredService(new RequisitionMonitoredService("SNMP"));
RequisitionNode reqNode = new RequisitionNode();
reqNode.setNodeLabel(nodeLabel);
reqNode.setForeignId(foreignId);
reqNode.putInterface(reqIface);
for (String category : categories) {
reqNode.putCategory(new RequisitionCategory(category));
}
if (deviceUsername != null) {
reqNode.putAsset(new RequisitionAsset("username", deviceUsername));
}
if (devicePassword != null) {
reqNode.putAsset(new RequisitionAsset("password", devicePassword));
}
if (enablePassword != null) {
reqNode.putAsset(new RequisitionAsset("enable", enablePassword));
}
if (accessMethod != null) {
reqNode.putAsset(new RequisitionAsset("connection", accessMethod));
}
if (autoEnable != null) {
reqNode.putAsset(new RequisitionAsset("autoenable", autoEnable));
}
// Now save it to the requisition
try {
Requisition req = m_foreignSourceRepository.getRequisition(foreignSource);
req.putNode(reqNode);
log().debug("saving requisition node");
m_foreignSourceRepository.save(req);
} catch (ForeignSourceRepositoryException e) {
throw new RuntimeException("unable to retrieve foreign source '" + foreignSource + "'", e);
}
log().debug("creating database node");
// Create the basic node
OnmsDistPoller dp = m_distPollerDao.get("localhost");
OnmsNode node = new OnmsNode(dp);
node.setType("A");
node.setForeignSource(foreignSource);
node.setForeignId(foreignId);
node.setLabel(nodeLabel);
node.getAssetRecord().setAutoenable(autoEnable);
node.getAssetRecord().setConnection(accessMethod);
node.getAssetRecord().setEnable(enablePassword);
node.getAssetRecord().setUsername(deviceUsername);
node.getAssetRecord().setPassword(devicePassword);
OnmsIpInterface iface = new OnmsIpInterface(ipAddress, node);
iface.setIsManaged("M");
iface.setIsSnmpPrimary(new PrimaryType('P'));
// these are automatically added to the interface by the constructor
new OnmsMonitoredService(iface, getServiceType("ICMP"));
new OnmsMonitoredService(iface, getServiceType("SNMP"));
log().debug("saving database node");
m_nodeDao.save(node);